package com.wdcloud.netlibrary.request;

import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * <p>
 * 请求体为json字符串
 */

public class ByteRequest extends BaseRequest<ByteRequest> {

    public byte[] bytes;

    @Override
    public ByteRequest byteContent(byte[] bytes) {
        this.bytes = bytes;
        return this;
    }

    @Override
    protected void buildRequest() {
        if (url == null) {
            throw new RuntimeException("请求路径不能为空");
        }

        if (bytes != null) {
            RequestBody body = RequestBody.create(MediaType.parse("text/plain"), bytes);
            builder.url(url).post(body);
        } else {
            builder.url(url);
        }
    }
}
